package com.ruoyi.project.zxcrm.mapper;

import com.ruoyi.project.zxcrm.domain.CrmSmsLog;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CrmSmsSendLogMapper {

    public int insertSmsLog(CrmSmsLog crmSmsLog);

    @Select("select count(sms_log_id) from sms_log where customer_phone = #{phone}")
    public int queryPhoneNum(@Param("phone") String mobile);

    @ResultMap(value = "userMap")
    @Select("select sms_log_id,sms_log_name,status,create_time,sms_day,customer_phone,t_id " +
            "from sms_log where customer_phone = #{phone} and status = 0")
    public List<CrmSmsLog> queryPhoneNumCustomer(@Param("phone") String mobile);

    @Results(id = "userMap", value = {
            @Result(property = "smsLogId", column = "sms_log_id"),
            @Result(property = "smsLogName", column = "sms_log_name"),
            @Result(property = "status", column = "status"),
            @Result(property = "smsDay", column = "sms_day"),
            @Result(property = "customerPhone", column = "customer_phone"),
            @Result(property = "tId", column = "t_id")
    })
    @Select("select sms_log_id,sms_log_name," +
            "status,create_time,sms_day," +
            "customer_phone,t_id " +
            "from sms_log " +
            "where status = 0 AND datediff(now(),create_time)=0")
    public List<CrmSmsLog> querySmsLogList();


    @Update("update sms_log set status = #{status},sms_day = #{smsDay},log_err_info= #{logErrInfo}" +
            "where sms_log_id = #{smsLogId}")
    public int updateSmsLog(CrmSmsLog crmSmsLog);

    @Select("SELECT count(sms_log_id) from sms_log")
    public int selectLogSum();

    @Select("SELECT count(sms_log_id) from sms_log where status = 0")
    public int selectLogUnsetSum();

    @Select("select count(sms_log_id) from sms_log  where status = 0 AND datediff(now(),create_time)=-1")
    public int SelectToDay();

    @Select("select count(sms_log_id) from sms_log  where status = 1 AND datediff(now(),create_time)=0")
    public int SelectToDaySucceed();

    public int updateStatus(@Param("a") List<CrmSmsLog> list);
}
